﻿

class Config_Json_Tcp_Server
{
    static string 文件名 = "config_tcp_server.json";
    public string server_port = "4196";
    public bool 加回车 = false;
    public string 指令1 = "";
    public string 指令2 = "";
    public string 指令3 = "";
    public string 指令4 = "";
    public string 指令5 = "";
    public string 指令6 = "";
    public string 指令7 = "";
    public string 指令8 = "";
    public string 指令9 = "";
    public string 指令10 = "";

    public string 用途1 = "";
    public string 用途2 = "";
    public string 用途3 = "";
    public string 用途4 = "";
    public string 用途5 = "";
    public string 用途6 = "";
    public string 用途7 = "";
    public string 用途8 = "";
    public string 用途9 = "";
    public string 用途10 = "";

    public static void save(Config_Json_Tcp_Server config)
    {
        string jsontxt = Newtonsoft.Json.JsonConvert.SerializeObject(config, Newtonsoft.Json.Formatting.Indented);
        using (System.IO.StreamWriter writer = new System.IO.StreamWriter(文件名))
        {
            writer.WriteLine(jsontxt);
            writer.Close();
        }
    }
    public static void save(Config_Json_Tcp_Server config, string path)
    {
        string jsontxt = Newtonsoft.Json.JsonConvert.SerializeObject(config, Newtonsoft.Json.Formatting.Indented);
        using (System.IO.StreamWriter writer = new System.IO.StreamWriter(path))
        {
            writer.WriteLine(jsontxt);
            writer.Close();
        }
    }


    public static Config_Json_Tcp_Server ReadAll()
    {
        Config_Json_Tcp_Server config = new Config_Json_Tcp_Server();
        if (System.IO.File.Exists(文件名) == false)
        {
            string jsontxt = Newtonsoft.Json.JsonConvert.SerializeObject(config);
            using (System.IO.StreamWriter writer = new System.IO.StreamWriter(文件名, true))
            {
                writer.Write(jsontxt);
                writer.Close();
            }
            return config;
        }

        string tt = System.IO.File.ReadAllText(文件名);
        config = Newtonsoft.Json.JsonConvert.DeserializeObject<Config_Json_Tcp_Server>(tt);
        return config;
    }
}

class Config_Json_Tcp_Client
{
    static string 文件名 = "config_tcp_client.json";
    public string server_ip = "127.0.0.1";
    public string server_port = "8080";

    public bool 加回车 = false;

    public string 指令1 = "";
    public string 指令2 = "";
    public string 指令3 = "";
    public string 指令4 = "";
    public string 指令5 = "";
    public string 指令6 = "";
    public string 指令7 = "";
    public string 指令8 = "";
    public string 指令9 = "";
    public string 指令10 = "";

    public string 用途1 = "";
    public string 用途2 = "";
    public string 用途3 = "";
    public string 用途4 = "";
    public string 用途5 = "";
    public string 用途6 = "";
    public string 用途7 = "";
    public string 用途8 = "";
    public string 用途9 = "";
    public string 用途10 = "";

    public static void save(Config_Json_Tcp_Client config)
    {
        string jsontxt = Newtonsoft.Json.JsonConvert.SerializeObject(config, Newtonsoft.Json.Formatting.Indented);
        using (System.IO.StreamWriter writer = new System.IO.StreamWriter(文件名))
        {
            writer.WriteLine(jsontxt);
            writer.Close();
        }
    }
    public static void save(Config_Json_Tcp_Client config, string path)
    {
        string jsontxt = Newtonsoft.Json.JsonConvert.SerializeObject(config, Newtonsoft.Json.Formatting.Indented);
        using (System.IO.StreamWriter writer = new System.IO.StreamWriter(path))
        {
            writer.WriteLine(jsontxt);
            writer.Close();
        }
    }


    public static Config_Json_Tcp_Client ReadAll()
    {
        Config_Json_Tcp_Client config = new Config_Json_Tcp_Client();
        if (System.IO.File.Exists(文件名) == false)
        {
            string jsontxt = Newtonsoft.Json.JsonConvert.SerializeObject(config);
            using (System.IO.StreamWriter writer = new System.IO.StreamWriter(文件名, true))
            {
                writer.Write(jsontxt);
                writer.Close();
            }
            return config;
        }

        string tt = System.IO.File.ReadAllText(文件名);
        config = Newtonsoft.Json.JsonConvert.DeserializeObject<Config_Json_Tcp_Client>(tt);
        return config;
    }
}